home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / rmtlog1a / cfileout.cls next >
Text File  |  1999-03-21  |  3KB  |  170 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "CFileOutputHandler"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Attribute VB_Ext_KEY = "SavedWithClassBuilder" ,"Yes"
  15. Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
  16. Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
  17. Option Explicit
  18.  
  19. Public Append As Boolean
  20.  
  21. Private mvarFileName As String
  22. Private hFile As Integer
  23.  
  24. Private Const fihNoCurrentFile As Long = -1
  25. Public Sub CloseFile()
  26.  
  27.   If hFile <> fihNoCurrentFile Then
  28.     Close #hFile
  29.     hFile = fihNoCurrentFile
  30.   End If
  31.  
  32. End Sub
  33.  
  34. Public Property Get IsOpen() As Boolean
  35. Attribute IsOpen.VB_UserMemId = 0
  36. Attribute IsOpen.VB_MemberFlags = "200"
  37.  
  38.   IsOpen = (hFile <> fihNoCurrentFile)
  39.  
  40. End Property
  41.  
  42. Public Function WriteFile(FileContents As String) As Boolean
  43.  
  44.   On Error GoTo WriteFileError
  45.  
  46.   If hFile <> fihNoCurrentFile Then
  47.     CloseFile
  48.     If OpenFile Then
  49.       Print #hFile, FileContents;
  50.       CloseFile
  51.     End If
  52.   End If
  53.  
  54.   WriteFile = True
  55.   Exit Function
  56.   
  57. WriteFileError:
  58.   MsgBox Err.Description, vbCritical, "Write File"
  59.  
  60. End Function
  61.  
  62. Public Function OpenFile(Optional FileName As String = "") As Boolean
  63.  
  64.   On Error GoTo OpenFileError
  65.  
  66.   If FileName <> "" Then
  67.     mvarFileName = FileName
  68.   End If
  69.  
  70.   CloseFile
  71.   
  72.   hFile = FreeFile
  73.   
  74.   If Append Then
  75.     Open mvarFileName For Append As #hFile
  76.   Else
  77.     Open mvarFileName For Output As #hFile
  78.   End If
  79.   
  80.   OpenFile = True
  81.   Exit Function
  82.   
  83. OpenFileError:
  84.   MsgBox Err.Description, vbCritical, "Open File"
  85.  
  86. End Function
  87. Public Function WriteBytes(Bytes() As Byte) As Boolean
  88.  
  89.   Dim sTemp As String
  90.  
  91.   On Error GoTo WriteBytesError
  92.  
  93.   LSet sTemp = Bytes()
  94.  
  95.   If hFile <> fihNoCurrentFile Then
  96.     Print #hFile, sTemp;
  97.   End If
  98.  
  99.   WriteBytes = True
  100.   Exit Function
  101.   
  102. WriteBytesError:
  103.   MsgBox Err.Description, vbCritical, "WriteBytes"
  104.  
  105. End Function
  106.  
  107. Public Function WriteChars(WriteString As String) As Boolean
  108.  
  109.   On Error GoTo WriteCharsError
  110.  
  111.   If hFile <> fihNoCurrentFile Then
  112.     Print #hFile, WriteString;
  113.   End If
  114.  
  115.   WriteChars = True
  116.   Exit Function
  117.   
  118. WriteCharsError:
  119.   MsgBox Err.Description, vbCritical, "WriteChars"
  120.  
  121. End Function
  122.  
  123. Public Function WriteLine(Line As String) As Boolean
  124.  
  125.   On Error GoTo WriteLineError
  126.  
  127.   If hFile <> fihNoCurrentFile Then
  128.     Print #hFile, Line
  129.   End If
  130.  
  131.   WriteLine = True
  132.   Exit Function
  133.   
  134. WriteLineError:
  135.   MsgBox Err.Description, vbCritical, "Write Line"
  136.   
  137. End Function
  138.  
  139.  
  140. Private Sub Class_Initialize()
  141.  
  142.   hFile = fihNoCurrentFile
  143.   mvarFileName = ""
  144.     
  145. End Sub
  146.  
  147.  
  148.  
  149. Public Property Get FileName() As String
  150.  
  151.   FileName = mvarFileName
  152.  
  153. End Property
  154.  
  155. Public Property Let FileName(ByVal vNewValue As String)
  156.   
  157.   CloseFile
  158.   
  159.   mvarFileName = vNewValue
  160.   
  161. End Property
  162.  
  163. Private Sub Class_Terminate()
  164.  
  165.   CloseFile
  166.   
  167. End Sub
  168.  
  169.  
  170.